import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const viewRouter = new Router({
  routes: [
    {
      path: '/',
      component: ()=> import('src/views_token/ytaBind.vue'),
      meta: {
        title: '綁定YTA地址'
      }
    },
    {
      path: '/ytaExchange',
      component: ()=> import('src/views_token/ytaExchange.vue'),
      meta: {
        title: 'CVNT兑换YTA'
      }
    },
    {
      path: '/ytaNewAddress',
      component: ()=> import('src/views_token/ytaNewAddress.vue'),
      meta: {
      title: 'CVNT兑换YTA'
    }
    },
    {
      path: '/pc',
      component: ()=> import('views_app/miningPC.vue'),
      meta: {
        title: '邀请矿工绑定'
      }
    },
    {
      path: '/nodeDetail',
      component: ()=> import('views_app/miningNodeDetail.vue'),
      meta: {
        title: '邀请矿工绑定'
      }
    },
    {
      path: '/node',
      component: ()=> import('views_app/DataNode.vue'),
      meta: {
        title: '邀请矿工绑定'
      }
    }
  ]
})

viewRouter.beforeEach((to, from, next) => {
  // if (to.meta.title) {
  //   document.title = to.meta.title
  // }
  let uid = to.query.uid || localStorage.getItem('uid')
  let token = to.query.token || localStorage.getItem('token')
  next()
  setTimeout(()=>{
    localStorage.setItem('uid', uid)
    localStorage.setItem('token', token)
  },40)
})


export default viewRouter
